home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 663 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: Rezonet.net!news
  2. From: ray@ultimate-tech.com (Ray Dunn)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: Terminating program at EOF
  5. Date: 8 Jan 1996 05:33:43 GMT
  6. Organization: Ultimate Technographics Inc.
  7. Message-ID: <4cqabn$if9@ns.RezoNet.NET>
  8. References: <4cn66j$5r0@fnpx20.fnal.gov>
  9. NNTP-Posting-Host: 204.19.230.7
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In referenced article, Stephen Field says...
  15. >I've written a program that does the job, but it doesn't stop when it 
  16. >reaches the end of the file....
  17.  
  18. >  char c_old=' ',c_new=' ';     /* check for newlines with chars */
  19. > [much snipped]
  20. >/*  while((c_new=fgetc(fptr_read))!=EOF){ */ /* old method for 
  21. >                                               removing EOF bug */
  22. >    while(c_new!=EOF){                       /* new method, still 
  23. >                                               doesn't work */
  24. >      c_new=fgetc(fptr_read);
  25.  
  26. After very quick scan of your code, there may be other problems:
  27. fgetc returns an *int* and EOF has the value -1.  You assign it to a 
  28. char, so if your chars are unsigned "c_new == EOF" is never true.
  29. -- 
  30. Ray Dunn (opinions are my own) | Phone: (514) 938 9050
  31. Montreal                       | Phax : (514) 938 5225
  32. ray@ultimate-tech.com          | Home : (514) 630 3749
  33.  
  34.